package com.jie.langlangmall.portal.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.portal.domain.MemberReadHistory;
import com.jie.langlangmall.portal.service.MemberReadHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/27
 * @Email 3217998214@qq.com
 * @Description 会员商品浏览记录管理
 */
@RestController
@Tag(name = "MemberReadHistoryController", description = "会员商品浏览记录管理")
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {

    @Autowired
    private MemberReadHistoryService memberReadHistoryService;

    @Operation(summary = "添加浏览记录")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody MemberReadHistory memberReadHistory) {
        memberReadHistoryService.create(memberReadHistory);
        return CommonResult.success();
    }

    @Operation(summary = "删除浏览记录")
    @PostMapping("/delete")
    public CommonResult<?> delete(@RequestParam("ids") List<String> ids) {
        memberReadHistoryService.delete(ids);
        return CommonResult.success();
    }

    @Operation(summary = "清空浏览记录")
    @PostMapping("/clear")
    public CommonResult<?> clear() {
        memberReadHistoryService.clear();
        return CommonResult.success();
    }

    @Operation(summary = "分页获取浏览记录")
    @GetMapping("/list")
    public CommonResult<CommonPage<MemberReadHistory>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<MemberReadHistory> page = memberReadHistoryService.list(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

}
